namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System.Xml.Serialization;
    using SimpleWebServices;
    using Xunit;

    public sealed class ParagraphFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<Paragraph>()
                .DerivesFrom<InnerElements>()
                .IsConcreteClass()
                .IsUnsealed()
                .HasDefaultConstructor()
                .Implements<IXmlSerializable>()
                .XmlRoot("p")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            Paragraph expected = new Paragraph(new Name("id"))
            {
                Class = "class",
                Language = "fr",
                Title = "title",
                Elements =
                {
                    new TextString("Some text")
                }
            };

            string xml = "<p id='id' class='class' lang='fr' title='title'>Some text</p>";
            Paragraph actual = xml.Deserialize<Paragraph>();

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }

        [Fact]
        public void deserializeEmpty()
        {
            Assert.NotNull("<p />".Deserialize<Paragraph>());
        }

        [Fact]
        public void serialize()
        {
            Paragraph obj = new Paragraph(new Name("id"))
            {
                Class = "class",
                Language = "fr",
                Title = "title",
                Elements =
                {
                    new TextString("Some text")
                }
            };

            string xpath = "1=count(/p[@id='id'][@class='class'][@lang='fr'][@title='title'][text()='Some text'])";

            Assert.True((bool)obj.Serialize().CreateNavigator().Evaluate(xpath));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new Paragraph());
        }

        [Fact]
        public void ctor_Name()
        {
            Assert.NotNull(new Paragraph(new Name("id")));
        }

        [Fact]
        public void ctor_NameNull()
        {
            Assert.NotNull(new Paragraph(null));
        }

        [Fact]
        public void op_Deserialize_string_string_string()
        {
            Paragraph expected = new Paragraph(new Name("id"))
            {
                Class = "class",
                Language = "fr",
                Title = "title",
                Elements =
                {
                    new TextString("Some text")
                }
            };

            string xml = "<p id='id' class='class' lang='fr' title='title'>Some text</p>";
            Paragraph actual = new Paragraph().Deserialize("p", null, xml) as Paragraph;

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }
    }
}